<template>
  <div style="padding:30px;">
    <el-alert :closable="false" title="用户管理"/>
    <el-row :gutter="20">


      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            node-key="deptId"
            ref="tree"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />
        </div>
        <div class="head-container">

        </div>

      </el-col>

      <!--  用户表单  -->

      <el-col :span="20" :xs="24">
        <el-form :model="queryParams"
                 ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="用户名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入用户名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="手机号码" prop="phonenumber">
            <el-input
              v-model="queryParams.phonenumber"
              placeholder="请输入手机号码"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="queryParams.status"
              v-if="dict.sys_normal_disable"
              placeholder="用户状态"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="dd in dict.sys_normal_disable.dictData"
                :key="dd.dictCode"
                :label="dd.dictLabel"
                :value="dd.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery()">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery()">重置</el-button>
          </el-form-item>
        </el-form>

        <!--    用户按钮-->
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd()"

            >新增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleEdit"

            >修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
            >删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="handleImport"

            >导入
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"

            >导出
            </el-button>

          </el-col>
          <el-row type="flex" justify="end">

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getUserPage(this.current,this.size)"
                           :columns="columns"></right-toolbar>
          </el-row>

        </el-row>
        <!--    用户表格-->
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="userList"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange">

          <el-table-column type="selection" :selectable="checkSelect" fixed width="50" align="center" >

          </el-table-column>
          <el-table-column
            fixed
            label="用户编号"
            align="center"
            width="120">
            <template slot-scope="scope">{{ scope.row.userId }}</template>
          </el-table-column>
          <el-table-column
            prop="userName"
            label="姓名"
            align="center"
            v-if="columns[0].visible"
            width="120">
          </el-table-column>
          <el-table-column
            prop="nickName"
            label="昵称"
            align="center"
            v-if="columns[1].visible"
            width="100px"
          >

          </el-table-column>
          <el-table-column

            label="部门"
            align="center"
            width="100px"
            v-if="columns[2].visible"
          >
            <template slot-scope="scope">{{ scope.row.dept.deptName }}</template>
          </el-table-column>

          <el-table-column
            prop="phonenumber"
            label="手机号码"
            align="center"
            width="150px"
            v-if="columns[3].visible"
          >
          </el-table-column>
          <el-table-column
            prop="email"
            label="邮箱"
            align="center"
            width="150px"
            v-if="columns[4].visible"
          >
          </el-table-column>
          <el-table-column
            label="性别"
            align="center"
            width="50px"
            v-if="columns[5].visible"
          >
            <template slot-scope="scope">{{ scope.row.sex == 0 ? '男' : '女' }}</template>
          </el-table-column>

          <el-table-column label="状态" align="center" width="100px" v-if="columns[6].visible">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                :disabled="scope.row.userId==1"
                active-value="0"
                inactive-value="1"
                active-color="#13ce66"
                inactive-color="#ff4949"
                @change="changeStatus(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>

          <el-table-column
            prop="createTime"
            label="创建时间"
            align="center"
            width="150px"
            v-if="columns[7].visible"
          >
          </el-table-column>

          <el-table-column label="操作" align="center" width="250px" fixed="right">
            <template slot-scope="scope" >
              <el-button
                size="mini"
                type="success"
                width="60px"
                :disabled="scope.row.userId==1"
                @click="handleEdit(scope.$index, scope.row)">编辑
              </el-button>
              <el-button
                size="mini"
                type="danger"
                :disabled="scope.row.userId==1"
                @click="handleDelete(scope.$index, scope.row)">删除
              </el-button>
<!--              <el-button-->
<!--                size="mini"-->
<!--                type="primary"-->
<!--                icon="el-icon-loading"-->
<!--                :disabled="scope.row.userId==1"-->
<!--                @click="handleDelete(scope.$index, scope.row)">更多-->
<!--              </el-button>-->


<!--              <el-button-->
<!--                size="mini"-->
<!--                type="success"-->
<!--                width="60px"-->
<!--                v-if="scope.row.userId!=1"-->
<!--                @click="handleEdit(scope.$index, scope.row)">编辑-->
<!--              </el-button>-->
<!--              <el-button-->
<!--                size="mini"-->
<!--                type="danger"-->
<!--                v-if="scope.row.userId!=1"-->
<!--                @click="handleDelete(scope.$index, scope.row)">删除-->
<!--              </el-button>-->
<!--              <el-button-->
<!--                size="mini"-->
<!--                type="primary"-->
<!--                icon="el-icon-loading"-->
<!--                v-if="scope.row.userId!=1"-->
<!--                @click="handleDelete(scope.$index, scope.row)">更多-->
<!--              </el-button>-->
            </template>

          </el-table-column>

        </el-table>

        <el-row type="flex" class="row-bg" justify="end">
          <el-pagination style=""
                         @size-change="handleSizeChange"
                         @current-change="handleCurrentChange"
                         :current-page="this.current"
                         :page-sizes="[5, 10, 15, 20]"
                         :page-size="this.size"
                         layout="total, sizes, prev, pager, next, jumper"
                         :total="this.total">
          </el-pagination>
        </el-row>
      </el-col>

    </el-row>

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户昵称" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请输入用户昵称" maxlength="30"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :normalizer="normalizer" :show-count="true" placeholder="请选择归属部门"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phonenumber">
              <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item v-if="form.userId == undefined" label="用户名称" prop="userName">
              <el-input v-model="form.userName" placeholder="请输入用户名称" maxlength="30"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
              <el-input v-model="form.password" placeholder="请输入用户密码" type="password" maxlength="20" show-password/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户性别" v-if="dict.sys_user_sex">
              <el-select v-model="form.sex" placeholder="请选择性别">
                                <el-option
                                  v-for="sex in dict.sys_user_sex.dictData"
                                  :key="sex.dictCode"
                                  :label="sex.dictLabel"
                                  :value="sex.dictValue"
                                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" v-if="dict.sys_normal_disable">
              <el-select v-model="form.status" placeholder="请选择状态">
                                <el-option
                                  v-for="dd in dict.sys_normal_disable.dictData"
                                  :key="dd.dictCode"
                                  :label="dd.dictLabel"
                                  :value="dd.dictValue"
                                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="岗位">
              <el-select v-model="form.postIds" placeholder="请选择岗位">
                <el-option
                  v-for="item in postOptions"
                  :key="item.postId"
                  :label="item.postName"
                  :value="item.postId"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="角色">
              <el-select v-model="form.roleIds" placeholder="请选择角色">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.roleId"
                  :label="item.roleName"
                  :value="item.roleId"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>


</template>

<script>
    export default {
        name: "User",
        data() {
            return {

                dicts:["sys_normal_disable","sys_user_sex"],
                dict:[],
                //表格加载
                loading:false,
                //是否显示搜索栏
                showSearch: true,
                userList: null,
                user: undefined,
                total: 0,
                //分页页数
                current: 1,
                //分页大小
                size: 5,
                // 是否显示弹出层
                open: false,

                // 选中数组
                ids: [],

                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,

                multipleSelection: [],
                //日期时间
                dateRange: [],
                // 部门名称
                deptName: undefined,
                // 部门树选项
                deptOptions: undefined,
                //弹出层标题名字
                title: "",
                // 岗位选项
                postOptions: [],
                // 角色选项
                roleOptions: [],

                // 表单参数
                form: {},
                //部门树
                defaultProps: {
                    children: "depts",
                    label: "deptName"
                },



                //添加或修改的选择树
                normalizer(node) {
                    if(node.children==null||node.children=='null'){
                        delete node.children;
                    }
                    return {
                        id: node.deptId,
                        label: node.deptName,
                        children: node.depts,
                    }
                },



                // 列信息
                columns: [
                    {key: 0, label: `用户姓名`, visible: true},
                    {key: 1, label: `用户昵称`, visible: true},
                    {key: 2, label: `用户部门`, visible: true},
                    {key: 3, label: `手机号码`, visible: true},
                    {key: 4, label: `用户邮箱`, visible: true},
                    {key: 5, label: `用户性别`, visible: true},
                    {key: 6, label: `用户状态`, visible: true},
                    {key: 7, label: `创建时间`, visible: true}
                ],
                rules: {
                    userName: [
                        {required: true, message: "用户名称不能为空", trigger: "blur"},
                        {min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur'}
                    ],
                    nickName: [
                        {required: true, message: "用户昵称不能为空", trigger: "blur"}
                    ],
                    password: [
                        {required: true, message: "用户密码不能为空", trigger: "blur"},
                        {min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur'}
                    ],
                    email: [
                        {
                            type: "email",
                            message: "请输入正确的邮箱地址",
                            trigger: ["blur", "change"]
                        }
                    ],
                    phonenumber: [
                        {
                            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                            message: "请输入正确的手机号码",
                            trigger: "blur"
                        }
                    ]
                },

                queryParams: {
                    pageNum: 1,
                    pageSize: this.size,
                    userName: undefined,
                    phonenumber: undefined,
                    status: undefined,
                    deptId: undefined
                },

                // 用户导入参数
                upload: {
                    // 是否显示弹出层（用户导入）
                    open: false,
                    // 弹出层标题（用户导入）
                    title: "",
                    // 是否禁用上传
                    isUploading: false,
                    // 是否更新已经存在的用户数据
                    updateSupport: 0,
                    // 设置上传的请求头部
                    headers: { Authorization: "Bearer "  },
                    // 上传的地址
                    url: process.env.VUE_APP_BASE_API+"/user/import"
                }

            }
        },
        methods: {
            handleQuery() {
                console.log(this.queryParams)
                this.current=1;
                this.getUserPage(this.current,this.size)

            },


            // 筛选节点
            filterNode(value, data,node) {

                if (!value) return true;
                return data.deptName.indexOf(value) !== -1;
            },
            // 节点单击事件
            handleNodeClick(data) {
                console.log(data.deptId)
                this.queryParams.deptId = data.deptId;
                this.handleQuery();
            },

            //分页
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.size = val;
                this.getUserPage(this.current, val);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.current=val;
                this.getUserPage(val, this.size);
            },

            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.userId);
                console.log(this.$refs.multipleTable.selection[0].userId)
                this.single = selection.length != 1;
                this.multiple = !selection.length;
            },

            //判断是否可选
            checkSelect (row) {
                let isChecked = true;
                if (row.userId==1) { // 判断里面是否存在某个参数
                    isChecked = false
                } else {
                    isChecked = true
                }
                return isChecked
            },
            changeStatus(row){
                console.log(row)
                let text = row.status === "0" ? "启用" : "停用";
                this.$confirm('确认要"' + text + '""' + row.userName + '"用户吗？').then(function() {

                }).then(() => {

                    this.axios.put("user/user",row)
                        .then(res=>{

                        });
                    this.$message({
                        type: 'success',
                        message: '修改成功!'
                    });

                }).catch(function() {
                    row.status = row.status === "0" ? "1" : "0";
                });

            },


            // //表格显示
            // handleSelectionChange(val) {
            //     this.multipleSelection = val;
            // }, toggleSelection(rows) {
            //     if (rows) {
            //         rows.forEach(row => {
            //             this.$refs.multipleTable.toggleRowSelection(row);
            //         });
            //     } else {
            //         this.$refs.multipleTable.clearSelection();
            //     }
            // },
            //搜索
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.queryParams= {
                    pageNum: 1,
                        pageSize: this.size,
                        userName: undefined,
                        phonenumber: undefined,
                        status: undefined,
                        deptId: undefined
                }
                this.handleQuery();
            },
            resetForm(formName) {
                this.$refs[formName].resetFields()
            },

            //获取所有部门
            getAllDept() {
                this.axios.get("dept/depts")
                    .then(res => {

                        this.deptOptions = res.data;

                    })
            },
            //获取所有部门
            getAllPost(){
                this.axios.get("post/posts")
                    .then(res => {
                        console.log(res.data)
                        this.postOptions = res.data;
                        console.log(this.postOptions)
                    })
            },
            //获取所有角色
            getAllRole(){
                this.axios.get("role/allRoles")
                    .then(res => {
                        this.roleOptions = res.data;
                        console.log(this.roleOptions)
                    })
            },
            //获取字典数据
            getDictData(type){
                this.axios.get("dict/dictByType/"+type)
                    .then(res => {
                        this.dict = res.data;
                        console.log(this.dict)
                    })
            },

            //获取分页数据
            getUserPage(current, size) {
                this.loading=true;
                this.axios.post("user/users?current=" + current + "&size=" + size +"&date="+this.dateRange.join()
                ,this.qs.stringify(this.queryParams))
                    .then(res => {
                        console.log(res.data)
                        this.userList = res.data.records;
                        this.total = res.data.total;
                        this.loading=false;

                    })
            },
            //用户添加方法
            handleAdd() {
                this.reset();
                this.open = true;

            },



            //导入功能
            handleImport() {
                this.upload.title = "用户导入";
                this.upload.open = true;
            },
            //导出功能

            // 导出数据
            handleExport(){
                this.axios({
                    method: 'get',
                    url:'user/excel',
                    responseType: 'arraybuffer',
                })
                    .then(res =>{
                        console.log(res)
                        //使用Blob对象将后端返回的Arraybuffer格式得数据转成blob类型的数据 window.URL.createObjectURL(blob)可以把一个blob转成blobURL，用作图片显示，文件下载（不能再服务器上存储，只能在浏览器使用）
                        var b = new Blob([res.data], { type: 'application/vnd.ms-excel' });
                        // 使用URL对象将blob类型的数据生成一个在线下载的链接
                        var url = URL.createObjectURL(b);
                        // 然后我们使用a标签进行下载
                        var link = document.createElement('a');

                        // 设置导出的文件名
                        link.download = "字典类型";
                        link.href = url;
                        // 点击获取文件
                        link.click();

                        (err) => {
                            console.log(err);
                        }
                    })

            },
            //用户修改方法
            handleUpdate() {
                this.axios.put("user/user", this.user)
                    .then(res => {
                        if (res == "OK") {
                            this.$message({
                                message: '恭喜你，修改成功',
                                type: 'success'
                            });
                        }
                    })
            },
            submitForm: function () {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        console.log(this.form)
                        if (this.form.userId != undefined) {
                            console.log("************")
                            this.axios.put("user/user", this.qs.stringify(this.form))
                                .then(res => {

                                    if (res.data == "OK") {
                                        this.$message({
                                            message: '恭喜你，修改成功',
                                            type: 'success'
                                        });
                                        this.open = false;
                                        this.getUserPage(this.current, this.size);
                                    }
                                })
                        } else {
                            console.log("!!!!!!!!!!!!!!!!")
                            console.log(this.form)
                            this.axios.post("user/user",
                            this.qs.stringify(this.form))
                                .then(res=>{
                                    console.log(res)
                                    if (res.data == "添加成功"){
                                        this.$message({
                                            message: '恭喜你，添加成功',
                                            type: 'success'
                                        });
                                        this.open = false;
                                        this.getUserPage(this.current, this.size);
                                    }else{
                                        this.$message({
                                            message: '添加失败，用户名已存在',
                                            type: 'info'
                                        });
                                    }
                                })
                            // addUser().then(response => {
                            //     this.$modal.msgSuccess("新增成功");
                            //     this.open = false;
                            //     this.getList();
                            // });
                        }
                    }
                });
            },
            getRoleAndPost(id){
              this.axios.get("user/RAP?id="+id)
                  .then(res=>{
                      if (res.data.postIds!=-1){
                          this.form.postIds=res.data.postIds;
                          // this.form.postIds.push();
                      }
                      if (res.data.roleIds!=-1){
                          this.form.roleIds=res.data.roleIds;
                          // this.form.roleIds.push();
                      }
                  })
                console.log(this.form)
            },
            //表格修改按钮
            handleEdit(index, row) {
                console.log(this.$refs.multipleTable.selection)
                this.reset();
                if (row){
                    this.form = {
                        deptId:row.deptId,
                        email:row.email,
                        nickName:row.nickName,
                        phonenumber:row.phonenumber,
                        remark:row.remark,
                        sex:row.sex,
                        status:row.status,
                        userId:row.userId,
                        userName:row.userName,
                        postIds:[],
                        roleIds:[]
                    };
                }else{
                    let a=this.$refs.multipleTable.selection[0];
                    this.form = {
                        deptId:a.deptId,
                        email:a.email,
                        nickName:a.nickName,
                        phonenumber:a.phonenumber,
                        remark:a.remark,
                        sex:a.sex,
                        status:a.status,
                        userId:a.userId,
                        userName:a.userName,
                        postIds:[],
                        roleIds:[]
                    };
                }

                this.getRoleAndPost(this.form.userId);
                this.open = true;
            },
            handleDelete(index, row) {
                if (row){
                    this.ids=row.userId
                }else{
                    this.ids=this.ids.join()
                }
                console.log(this.ids)

                this.$confirm('此操作将永久删除该人员, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    console.log("-------------")
                    this.axios.delete("/user/deleteAll/"+this.ids)
                        .then(res=>{
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        })

                    console.log("*****************")


                    this.current=1;
                    this.getUserPage(this.current, this.size);
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },


            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    userId: undefined,
                    deptId: undefined,
                    userName: undefined,
                    nickName: undefined,
                    password: undefined,
                    phonenumber: undefined,
                    email: undefined,
                    sex: undefined,
                    status: undefined,
                    remark: undefined,
                    postIds: [],
                    roleIds: []
                };
                // this.resetForm("form");
            },
            getTestMap(){

                this.axios.get("dict/maps/"+this.dicts.join())
                    .then(res => {
                        this.dict = res.data;
                        console.log(this.dict)
                        console.log(this.dict.sys_normal_disable)
                    })
            },
            // 提交上传文件
            submitFileForm() {
                this.$refs.upload.submit();
            },
            // 文件上传中处理
            handleFileUploadProgress(event, file, fileList) {
                this.upload.isUploading = true;
            },
            // 文件上传成功处理
            handleFileSuccess(response, file, fileList) {
                this.upload.open = false;
                this.upload.isUploading = false;
                this.$refs.upload.clearFiles();
                this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
                this.getList();
            },
            /** 下载模板操作 */
            importTemplate() {
                this.download('system/user/importTemplate', {
                }, `user_template_${new Date().getTime()}.xlsx`)
            }

        },
        created() {
            this.getUserPage(this.current, this.size);
            this.getAllDept();
            this.getAllPost();
            this.getAllRole();
            this.getTestMap();
        },
        watch: {
            // 根据名称筛选部门树
            deptName(val,val2) {
                this.$refs.tree.filter(val);
            }
        }
    }
</script>

<style scoped>
  .el-alert {
    margin-bottom: 20px;
  }

</style>
